<template>
  <div class="dialog">
    <el-dialog
      title="审核未通过原因"
      :visible.sync="showDialog"
      width="35%"
      top="0"
      :close-on-click-modal="false"
      @close="cancel"
    >
      <el-form
        ref="ruleForm"
        label-position="left"
        :model="formData"
        :rules="rules"
        class="el-form"
      >
        <el-form-item label="未通过原因：" class="w100p" prop="reason">
          <el-input
            v-model="formData.reason"
            clearable
            :rows="2"
            type="textarea"
            placeholder="请输入未通过原因"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button class="cancelbtn" @click="cancel()">取 消</el-button>
        <el-button type="primary" class="savebtn" @click="save('ruleForm')">保 存</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import repairAuditApi from "@/api/equip-repair-manage/repair-audit";
export default {
  name: '',
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false
    },
    editObject: {
      type: [Object],
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      formData: {},
      rules: {
        reason: [
          { required: true, message: "请输入未通过原因", trigger: ["change", "blur"] }
        ]
      },
      showDialog: this.show
    };
  },

  watch: {
    show(v) {
      this.showDialog = v;
    }
  },
  created() {
  },
  mounted() {
  },
  methods: {
    save(formData) {
      console.log(formData);
      this.$refs[formData].validate(valid => {
        if (valid) {
          // 审核不通过
          this.formData.result = '审核未通过'
          this.formData.hitchApplyAuditCode = this.editObject.hitchApplyAuditCode;
          repairAuditApi.editApplyInnNew({...this.formData,
                                        personNo: sessionStorage.personNo,
                                        pass: false}).then(res => {
            if (res.code === 1) {
              this.$message.success("审核成功！");
              this.close()
            } else {
              this.$message.error("审核失败！");
            }
          });
        } else {
          return false;
        }
      });
    },
    close() {
      this.formData = {};
              this.$nextTick(() => {
        this.$refs['ruleForm']?.clearValidate();
      });
      this.$emit("closeDialog");
    },
    cancel() {
      this.formData = {};
              this.$nextTick(() => {
        this.$refs['ruleForm']?.clearValidate();
      });
      this.$emit("cancelDialog");
    }
  }
};
</script>

<style lang="scss" scoped>
</style>
